﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using ZHDJ.Core.Log;
using ZHDJ.Data;
using ZHDJ.Data.BLL;
using ZHDJ.Data.Models.Common;
using ZHDJ.WinService.Util;

namespace ZHDJ.WinService.Job
{
    /// <summary>
    /// 生成组织关系
    /// </summary>
    public class InitBranchRelationJob : JobBase
    {
       

        /// <summary>
        /// 执行业务锁
        /// </summary>
        private static Object BusinessLock = new Object();
        public override JobSetInfo JobSetInfo
        {
            get
            {
                return new JobSetInfo()
                {
                    JobGroup = "InitBranchRelationJobGroup",
                    JobName = "InitBranchRelationJob",
                    //
                    TriggerName = "InitBranchRelationJobTrigger",
                    Cron = ConfigHelper.InitBranchRelationJobIntervalCron
                };
            }
        }


        public override void RunBusiness(IJobExecutionContext context)
        {
            //LogHelper.Info("组织关系重置--开始");
            lock (BusinessLock)
            {
                var val = TempPara.GetInitBranchRelation();
                if (val == "1")
                {
                    LogHelper.Info("组织关系重置--开始", "InitBranchRelationJob");
                    TempPara.UpdateInitBranchRelation("0");
                    PartyOrg.InitPartyOrgBranchRelation();
                    LogHelper.Info("组织关系重置--结束", "InitBranchRelationJob");
                }
                
            }
        }

        

        public override void OnStop()
        {
            
        }
    }
}
